package gui;

import java.awt.Color;

import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.AbstractDocument;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;

import toolkit.Debug;

public class Chat extends JScrollPane
{
	JTextPane textPane;
	
	AbstractDocument document;
	
	SimpleAttributeSet bold, system;
	
	public Chat()
	{
		setVerticalScrollBarPolicy(VERTICAL_SCROLLBAR_ALWAYS);
		setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER);
		
		textPane = new JTextPane();
		textPane.setCaretPosition(0);
		textPane.setEditable(false);
		textPane.setBorder(null);

		setViewportView(textPane);
		
		document = (AbstractDocument) textPane.getStyledDocument();
		
		bold = new SimpleAttributeSet();
		StyleConstants.setBold(bold, true);
		
		system = new SimpleAttributeSet();
		StyleConstants.setForeground(system, new Color(0, 128, 0));
	}
	
	public void appendLine(String source, String message)
	{
		try
		{
			document.insertString(document.getLength(), source + ": ", bold);
			document.insertString(document.getLength(), message + "\n", null);
			
			textPane.setCaretPosition(document.getLength());
		}
		catch (Exception e)
		{
			Debug.log(e);
		}
	}
}
